using MicroMsg.Common.Utils;
using MicroMsg.Scene;
using MicroMsg.Scene.Voice;
using MicroMsg.Storage;
using System;
using System.IO.IsolatedStorage;
namespace MicroMsg.Plugin.DriftBottle.Scene
{
	public class ThrowVoiceBottleContext : IContextBase, IRecorderContext
	{
		private const string TAG = "ThrowVoiceBottleContext";
		public const int STATUS_INIT = 0;
		public const int STATUS_READY = 1;
		public const int STATUS_SENDING = 2;
		public const int STATUS_ERROR = 4;
		public const int STATUS_COMPLETE = 5;
		private const int MAX_SEND_BYTE_PER_PACK = 6000;
		private const int MIN_SEND_BYTE_PER_PACK = 2000;
		public int mStatus;
		public string talkerName = "";
		public string filename = "";
		public int mNetOffset;
		public byte[] mOutputBuffer;
		public int mVoiceTimeLength;
		public int mOutputLength;
		public string mClientMsgID = "";
		public int mSendingLength;
		private object mOutputBufLock = new object();
		public IsolatedStorageFileStream bigImageFileStream;
		public byte[] mVoiceBuffer;
		public ChatMsg chatMsgInfo;
		public NetSceneThrowBottle senceHandle;
		public int mEndFlag;
		public bool needToHandle()
		{
			return this.mStatus == 0;
		}
		public bool isRunning()
		{
			if (this.mStatus != 1)
			{
				if (this.mStatus != 2)
				{
					return false;
				}
			}
			return true;
		}
		public void onStop(byte[] voiceBuffer, int dataLength, int timeLength)
		{
			this.mOutputBuffer = new byte[dataLength];
			Buffer.BlockCopy(voiceBuffer, 0, this.mOutputBuffer, 0, dataLength);
			this.mVoiceTimeLength = timeLength;
			this.mOutputLength = dataLength;
			if (this.isInvalidShortVoice())
			{
				this.mStatus = 4;
				Log.smethod_1("ThrowVoiceBottleContext", "scene end with invalid short voice. ");
				return;
			}
			ThrowVoiceBottleService.setWaitSendContext(this);
		}
		public bool needToClean()
		{
			return this.mStatus == 5 || this.mStatus == 4;
		}
		public bool onAppendOutputData(byte[] buffer, int offset, int count)
		{
			return true;
		}
		public bool saveChatMsg()
		{
			return true;
		}
		public bool isInvalidShortVoice()
		{
			return this.mVoiceTimeLength < 1000;
		}
		public bool isNeedData()
		{
			return true;
		}
		public void onVoiceTimeChanged(int timeLength)
		{
			this.mVoiceTimeLength = timeLength;
		}
		public void onStartup(int creatTime, object args)
		{
		}
		public byte[] getBufferFromHead()
		{
			byte[] result;
			lock (this.mOutputBufLock)
			{
				int num = 6000;
				int num2 = this.mOutputLength - this.mNetOffset;
				if (6000 > num2)
				{
					num = num2;
				}
				if (num <= 0)
				{
					result = null;
				}
				else
				{
					byte[] array = new byte[num];
					Buffer.BlockCopy(this.mOutputBuffer, this.mNetOffset, array, 0, num);
					this.mSendingLength = num;
					result = array;
				}
			}
			return result;
		}
	}
}
